package com.lx.shopping.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.lx.bilibili.entity.Product;
import com.lx.bilibili.entity.ProductEx;
import org.apache.ibatis.annotations.Many;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.mapping.FetchType;

public interface ProductExMapper extends BaseMapper<Product> {

    @Results(
            id = "rm1",
            value = {
                    @Result(id = true, column = "id", property = "id"),

                    @Result(column = "id", property = "imageItems",
                            //@Many一对多
                            many = @Many(fetchType = FetchType.EAGER,
                                    select = "com.lx.shopping.dao.ProductDetailImageMapper.selectByProductId")),

                    @Result(column = "id", property = "pictureItems",
                            //@Many一对多
                            many = @Many(fetchType = FetchType.EAGER,
                                    select = "com.lx.shopping.dao.ProductPictureMapper.selectByProductId"))
            }
    )

    @Select("select * from product where id = #{id}")
    ProductEx selectProductById(int id);
}
